package design_pattern.factory.standardFactory;


import java.util.Scanner;

/**
 * @version 1.0.0
 * Created by cyd on 2022-06-06 15:04:48
 * @Description : 客户端
 */
public class Client {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入第1个数字：");
        int numberA = scanner.nextInt();

        System.out.println("请输入操作符：");
        String flag = scanner.next();

        System.out.println("请输入第2个数字：");
        int numberB = scanner.nextInt();


        // 为了满足开闭原则，将生成何种操作符的判断，下放给了client，增加了使用成本
        Operation operation = null;
        switch (flag) {
            case "+":
                operation = FactoryAdd.getInstance();
                break;
            case "-":
                operation = FactoryMul.getInstance();
                break;
            default:
                break;
        }
        assert operation != null;
        operation.setNumberA(numberA);
        operation.setNumberB(numberB);

        int result = operation.operate();
        System.out.println("结果为：" + result);
    }
}
